﻿Ext.define('app.ux.GSE.gsePanel',
{
    extend: 'Ext.panel.Panel',
    img: '',
    cdx: '',
    mol: '',
    mf: '',
    mw: '',
    width: 400,
    height: 400,
    border: true,
    html: '',
    initComponent: function () {
        var me = this;

        if (!me.mol || me.mol.length < 10) {
            me.mol = '';
            me.img = '';
        }

        this.tbar = [
            '->', {
                text: 'Paste',
                handler: function (e) {
                    me.mf = '';
                    me.mw = '';
                    this.pasteChemDraw();
                }, scope: this
            },
                {
                    text: 'Edit',
                    handler: function (e) {
                        this.editChemDraw();
                    }, scope: this
                }
                ,
            { text: 'Clear', handler: function () { this.clearChemDraw(); }, scope: this }
        ];
        me.callParent();
    },
    pasteChemDraw: function () {
        var me = this;
        _____CallChromeCompentId = me.getId();
        readChemdraw();
    },
    editChemDraw: function () {
        var me = this;
        if (me.cdx && me.cdx.length > 10) {
            openCdxEvent(me.cdx);
        }
        else
            if (me.mol && me.mol.length > 10) {
                openMolEvent(me.mol);
            }
            else {
                var ______cdx = 'VmpDRDAxMDAEAwIBAAAAAAAAAAAAAACAAAAAAAMADwAAAENoZW1EcmF3IDEyLjAIAA4AAAB1bnRpdGxlZC5jZHgEAhAAAAAAAAAAAAAAAAAAAAAAAAEJCAAAAAAAAAAAAAIJCAAAQOUBAECcAgAJAAANCAEAAQgHAQABOgQBAAE7BAEAAEUEAQABPAQBAAAMBgEAAQ8GAQABDQYBAABCBAEAAEMEAQAARAQBAAAKCAgAAwBgAMgAAwALCAgAAwAAAMgAAwAJCAQAAIACAAgIBACZmQEABwgEAJmZAAAGCAQAAAACAAUIBABmZg4ABAgCALQAAwgEAAAAeAAjCAEABQwIAQAAKAgBAAEpCAEAASoIAQABAggQAAAAJAAAACQAAAAkAAAAJAABAwIAAAACAwIAAQAAAzIACAD///////8AAAAAAAD//wAAAAD/////AAAAAP//AAAAAP////8AAAAA/////wAA//8AAQ8AAAABAAMA5AQFAEFyaWFsAAh4AAADAAABIAEgAAAAAAtmCKD/hP+IC+MJGANnBScD/AACAAABIAEgAAAAAAtmCKAAAQBkAGQAAAABAAEBAQAAAAEnDwABAAEAAAAAAAAAAAAAAAAAAgAZAZAAAAAAAGAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAGABgAAAAQCEAAAAAAAAAAAAADAzwIAABwCFggEAAAAJAAYCAQAAAAkABkIAAAQCAIAAQAPCAIAAQAAAAAAAAA=';
                openCdxEvent(______cdx);
            }
    },
    clearChemDraw: function () {
        var me = this;
        me.cdx = '';
        me.img = '';
        me.mol = '';
        me.update('<div style="color:red">-*-*-*-</div>');
    },
    showImg: function () {
        var me = this;

        if (me.mf == '') {
            //只获取一次mol以及对应的分子式 
            Ext.Ajax.request({
                params:  JSON.stringify({
                    mol: me.mol
                }),
                url: '/Prm/Substance/PostPngByMol',
                timeout: 60000,
                success: function (resp, opts) {
                    var json = Ext.decode(resp.responseText);
                    me.mf = json.mf;
                    me.mw = json.mw || json.mv;
                    me.fireEvent('afterCommit',me.mf, me.mw);
                },
                failure: function (resp, opts) {
                    var respText = Ext.util.JSON.decode(resp.responseText);
                    Ext.Msg.alert('系统提示', respText.error);
                }

            });
        }




        if (me.img.length > 10) {
            showImg(me.getId(), me.img, 10, 'middle');
        }
        else {
            me.update('<div style="color:red">-*-*-*-</div>');
        }
    }
})